import {
  Body,
  Controller,
  Get,
  Param,
  Post,
  Query,
  UploadedFiles,
  UseInterceptors,
} from '@nestjs/common';
import { CreateUserDto } from './dto/create-user.dto';
import { AnyFilesInterceptor } from '@nestjs/platform-express';
// import { UserService } from './user.service';

@Controller('user')
export class UserController {
  @Post('login')
  // body(@Body() ){
  //   return
  // }
  @Get('find')
  query(@Query('name') name: string, @Query('age') age: number) {
    return `received: name=${name},age=${age}`;
  }

  @Get(':id')
  urlParam(@Param('id') id: string) {
    return `received: id=${id}`;
  }

  // @Post()
  // body(@Body() createUserDto: CreateUserDto) {
  //   return `received: ${JSON.stringify(createUserDto)}`;
  // }

  @Post()
  body(@Body() createUserDto: CreateUserDto) {
    return `received: ${JSON.stringify(createUserDto)}`;
  }

  @Post()
  @UseInterceptors(
    AnyFilesInterceptor({
      dest: 'uploads/',
    }),
  )
  body2(
    @Body() createUserDto: CreateUserDto,
    @UploadedFiles() files: Array<Express.Multer.File>,
  ) {
    console.log(files);
    return `received: ${JSON.stringify(createUserDto)}`;
  }
}
